package com.rxmvp.rxmvpdemo;

import android.app.Application;
import android.content.Context;

import com.rxmvp.rxmvpdemo.global.DaggerGlobalComponent;
import com.rxmvp.rxmvpdemo.global.GlobalComponent;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

/**
 * 作者： huangRZ on 2017/1/21. 15:04
 * 邮箱：917647409@qq.com
 */
public class App extends Application {

    private static App mApp;
    private static GlobalComponent globalComponent;

    private RefWatcher refWatcher;

    @Override
    public void onCreate() {
        super.onCreate();
        mApp = this;
        initDagger2();

        //初始化检测内存泄漏的leakCanary
        if (LeakCanary.isInAnalyzerProcess(this)) {
            // This process is dedicated to LeakCanary for heap analysis.
            // You should not init your app in this process.
            return;
        }
        refWatcher = LeakCanary.install(this);

    }

    //获取一个检测指定对象是否发生内存泄漏的Watcher
    public static RefWatcher getRefWatcher(Context context) {
        App application = (App) context.getApplicationContext();
        return application.refWatcher;
    }

    private void initDagger2() {
        globalComponent = DaggerGlobalComponent.builder().build();
    }

    public static GlobalComponent getGlobalComponent(){
        return globalComponent;
    }

    public static App getApp(){
        return mApp;
    }


}
